package com.yhd.gmall.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.yhd.gmall.common.result.Result;
import com.yhd.gmall.model.product.BaseAttrInfo;
import com.yhd.gmall.model.product.BaseCategoryView;
import com.yhd.gmall.model.product.SkuInfo;
import com.yhd.gmall.model.product.SpuSaleAttr;
import com.yhd.gmall.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author yhd
 * @createtime 2020/9/22 10:04
 */
@RestController
@RequestMapping("api/product")
public class ProductApiController {

    @Autowired
    private ProductService productService;

    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId) {
        return productService.getSkuInfo(skuId);
    }

    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id")Long category3Id){
        return productService.getCategoryViewByCategory3Id(category3Id);
    }
    @GetMapping("inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        return productService.getSkuPrice(skuId);
    }
    @GetMapping("inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable("skuId") Long skuId, @PathVariable("spuId") Long spuId){
        return productService.getSpuSaleAttrListCheckBySku(skuId, spuId);
    }
    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId){
        return productService.getSkuValueIdsMap(spuId);
    }
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> list = productService.getBaseCategoryList();
        return Result.ok(list);
    }
    /**
     * 通过skuid集合来查询数据
     */
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId){
        return productService.getAttrList(skuId);
    }
}
